<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use QL\QueryList;

class QuerylistController extends Controller
{
    public function download($url, $path = 'images/')
    {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
      $file = curl_exec($ch);
      curl_close($ch);
      $filename = pathinfo($url, PATHINFO_BASENAME);
      $resource = fopen($path . $filename, 'a');
      fwrite($resource, $file);
      fclose($resource);
    }


    public function showBasic () {
        // $data = QueryList::get('http://img1.mm131.com/pic/2147/')->find('img')->attrs('src');
        // $res = $data->all();
        // $count = 0;
        // foreach ($res as $img) {
        //     if ($start > 23) {
        //         break;
        //     }
        //     $start =1;
        //     $filename = time();
        //     $path = "D:\mv\\";
        //     $filename = $path.$filename.mt_rand(1,10000).'.jpg';
        //     $dc = file_get_contents("http://img1.mm131.com/pic/2147/".$start.'jpg');
        //     //var_dump($img);
        //     //$filename = 'D:\mv';
        //     file_put_contents($filename, $dc);
        //     echo $filename,'<br/>';
        //    // download($img);
        //    $count++;
        //    $start++;
        // }
        // echo '<br/>',$count;
        $count = 1;
        while ($count < 24) {
            $dc = file_get_contents("http://img1.mm131.com/pic/2147/".$count.'.jpg');
            $filename = time();
            $path = "D:\mv\\";
            $filename = $path.$filename.mt_rand(1,10000).'.jpg';
            file_put_contents($filename, $dc);
            $count++;
            echo $count, '<br/>';
        }
        return view('querypics');
    }

    
}
